package com.toobigtofail.palette
{
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.utils.Input;
	
	public class PlaceholderEditButton extends Entity
	{
		[Embed(source="/assets/gfx/plus.png")] private static const PLUS_PNG:Class;
		[Embed(source="/assets/gfx/minus.png")] private static const MINUS_PNG:Class;
		
		private var _tray:Tray;
		private var _placeholderType:String;
		private var _type:String;
		
		public function PlaceholderEditButton(tray:Tray, placeholderType:String, x:Number=0, y:Number=0, type:String="plus")
		{
			this.x = x;
			this.y = y;
			
			var image:Image;
			switch(type) {
				case "plus":  image = new Image(PLUS_PNG);  break;
				case "minus": image = new Image(MINUS_PNG); break;
			}
			this.graphic = image;
			
			this.width = image.width;
			this.height = image.height;
			
			_tray = tray;
			_placeholderType = placeholderType;
			_type = type;
		}
		
		override public function update():void {
			super.update();
			
			if (Input.mousePressed && this.collidePoint(x,y,Input.mouseX,Input.mouseY)) {
				switch(_type) {
					case "plus":  _tray.addItemType(_placeholderType);      break;
					case "minus": _tray.subtractItemType(_placeholderType); break;
				}
			}
		}
	}
}